home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / teco.arc / COMAND.C < prev    next >
C/C++ Source or Header  |  1986-07-15  |  1KB  |  75 lines

  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. comand()
  6. {
  7. #include "teco.h"
  8.  
  9.     char last,this;
  10.     int  tmp;
  11.  
  12. reset:    memset(getbuf,'\33',getsiz);
  13.     getptr=0;
  14.     last=0;
  15.  
  16.     while (kbhit()) getch();
  17.     fprintf(stderr,"*");
  18.  
  19. loop:    tmp=getch();
  20.     this=toascii(tmp);
  21.  
  22.     if (this != 27 | last != 27) {
  23.         if (this == 8 | this == 127) {
  24.             if (!getptr) {
  25.                 fprintf(stderr,"\n");
  26.                 goto reset;
  27.             }
  28.             if (getbuf[getptr] == 13 | getbuf[getptr] == 9) {
  29.                 if (getbuf[getptr] == 9) fprintf(stderr,"\n");
  30.                 tmp=getptr;
  31.                 while (getbuf[--tmp] != 13 & tmp != 0);
  32.                 while (++tmp != getptr) echo(getbuf[tmp]);
  33.             } else {
  34.                 if (getbuf[getptr]<32 & getbuf[getptr]!=27) {
  35.                     fprintf(stderr,"\10 \10\10 \10");
  36.                 } else {
  37.                     fprintf(stderr,"\10 \10");
  38.                 }
  39.             }
  40.             getbuf[getptr]='\0';
  41.             getptr=getptr-1;
  42.             goto loop;
  43.         } else {
  44.             echo(this);
  45.             if (this == 21) {
  46.                 if (!getptr) {
  47.                     fprintf(stderr,"\n");
  48.                     goto reset;
  49.                 }
  50.                 tmp=getptr;
  51.                 while (getbuf[tmp] !=13 & --tmp !=0);
  52.                 if (!tmp) {
  53.                     fprintf(stderr,"\n");
  54.                     goto reset;
  55.                 }
  56.                 getptr=tmp;
  57.                 echo('\15');
  58.             } else {
  59.                 if (getptr > getsiz) {
  60.                    fprintf(stderr,"?MEM, Memory overflow\n\7");
  61.                    goto reset;
  62.                 }
  63.                 getbuf[++getptr]=this;
  64.                 if (this == 13) {
  65.                     this=10;
  66.                     getbuf[++getptr]=this;
  67.                 }
  68.             }
  69.             last=this;
  70.             goto loop;
  71.         }
  72.     }
  73.     fprintf(stderr,"$\n");
  74. }
  75.